<template>
<div>
    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="zjldetailViewData"
        :height="'auto'"
        :isToperInfo="false"
        :isColumnFilter="false"
        :isSelectColumn="false"
        :columns="columns"
        :dataSource="tableList"
        :onColumnsChange="columns => (this.columns = columns)"
      >
      </FilterTable>
      <div style="height:30px;"></div>
      <FormPanel ref="formPanel" :list="formList" :isSubmitBtn="false" :collapse="false" />
     <div
        :style="{
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'center'
        }"
      >
        <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>
        <multiuse-button size="small" type="primary" :click="dataHandle.bind(this, 60771002)" :disabled="isPass">通过</multiuse-button>
        <multiuse-button size="small" type="primary" :click="dataHandle.bind(this, 60781003)" :disabled="isReject">驳回</multiuse-button>
        <multiuse-button size="small" :click="dataHandle.bind(this, 'close')">关闭</multiuse-button>
      </div>
    </Spin>
    </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportExcel, submitData,passData } from '@/api/omFinance/CRReportManage/BalanceSheetQuery';
import moment from 'moment';
import { exportExcelFile } from '@/utils/index';
export default {
  name: 'detailViewOEM',
  mixins: [dictionary],
  props: {
    formData: {
      type: Array,
      default: () => ({})
    },
    requestId:{
      type: Number,
      default: () => ({})
    },
    year:{
      type: String,
      default: () => ({})
    },
    month:{
      type: String,
      default: () => ({})
    },
    viewStatus:{
      type: Number,
      default: () => ({})
    }
  },
  components: {
  },
    data() {
    this.BaseTable = null;
    return {
      columns: this.createdTable(),
      formList: this.createdFrom1(),
      isDisabled: true,
      exportLoading: false,
      tableList:this.formData,
      isPass:this.viewStatus == 60781003?true:false,
      isReject:this.viewStatus == 60781004?true:false,
    };
    
  },
    mounted() {
      this.saveData = Object.assign({}, this.saveData, '');
  },
  methods: {
   // 驳回
    async dataHandle(status) {
       console.log(status);
      if(status == 'close'){
        console.log('关闭');
        this.$emit('close');
        return;
      }
      if(status == 60781003){
        this.formList[0].rules[0].required = true;
        console.log('驳回');
        this.$refs.formPanel.SUBMIT_FORM();
        if (!this.formList[0].initialValue) return;
      }else{
        this.formList[0].rules[0].required = false;
        console.log('通过');
        this.$refs.formPanel.SUBMIT_FORM();
      }
      
      this.saveData.id = this.requestId ? this.requestId : ''; // Id


       if(status == 60781003){
        //驳回
        this.saveData.balanceStatus = status; // 状态
        this.saveData.checkDesc = this.formList[0].initialValue;
        let res = await submitData(this.saveData);
        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '操作成功' });
          this.$emit('close');
          this.$emit('refrish');
        }
      }else{
        //通过
        let res = await passData(this.saveData);
        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '操作成功' });
          this.$emit('close');
          this.$emit('refrish');
        }
      }

    },
        // 导出
    async exportHandle() {

     console.log('indexExport');

      await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.exportLoading = true;
          let param = { id: this.requestId };
          exportExcel(param)
            .then(response => {
              exportExcelFile(response.data, '利润表查询');
              this.exportLoading = false;
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
   createdFrom1() {
      return [
        {
          type: 'TEXT_AREA',
          label: '驳回意见',
          fieldName: 'checkDesc',
          initialValue: '',
          selfCols: 3,
          disabled: this.isDisabled,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        }
      ];
    },
     createdTable() {
      return [
        {
          title: '利润表',
          dataIndex: 'column1',
          filterType: 'input',
          align: 'center'
        },
        {
          title: '',
          dataIndex: 'column2',
          filterType: 'input',
          align: 'center'
        },
        {
          title: '',
          dataIndex: 'column3',
          filterType: 'input',
          align: 'center'
        },
        {
          title: `月度：${this.year}年${this.month}月`,
          dataIndex: 'column4',
          filterType: 'input',
          align: 'center'
        }
      ];
    } 
  }
}
</script>
